package com.esd.listener;

import java.io.IOException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.util.FalsifyingWebConnection;

public class SimpleConectionListener extends FalsifyingWebConnection {

	// private static final Logger LOGGER =
	// LoggerFactory.getLogger(SimpleConectionListener.class);

	public static String resurl = "";
	public static String resurl1 = "";
	public static String resurl2 = "";
	public static String resurl3 = "";
	public static String resurl4 = "";
	public static boolean loginFlag = false;
	public SimpleConectionListener(WebClient webClient) throws IllegalArgumentException {
		super(webClient);
	}

	@Override
	public synchronized WebResponse getResponse(WebRequest request) throws IOException {
		// 得到了这个响应，你想怎么处理就怎么处理了，不多写了

		WebResponse response = super.getResponse(request);
		String url = response.getWebRequest().getUrl().toString();
		if (check(url)) {
			return createWebResponse(response.getWebRequest(), "", "application/javascript", 200, "Ok");
		}
		return response;
	}

	public boolean check(String url) {
		System.out.println(url);
		if (url.startsWith("http://b2c.csair.com/B2C40/modules/permissionnew/main/passenger.html?")) {
			resurl = url;
		}
		
		if (url.startsWith("http://b2c.csair.com/B2C40/modules/ordernew/orderManagementFrame.jsp")) {
			loginFlag = true;
			resurl1 = url;
		}
		
		if (url.startsWith("http://skypearl.csair.com/skypearl/cn/loginPage.action?")) {
			resurl2= url;
		}
		if (url.startsWith("http://skypearl.csair.com/skypearl/cn/memberArea.action?")) {
			loginFlag = true;
			resurl3= url;
		}
		if (url.startsWith("http://b2c.csair.com/B2C40/modules/common/langConfig/null/order.xml")) {
			loginFlag = true;
			resurl4= url;
		}
		
		return false;
	}

}
